/* Copyright  2009
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 * @filename: esql_methods.h
 */

#ifndef __LIBCLIENT_METHODS_H__
#define __LIBCLIENT_METHODS_h__

#include "esql.h"
#include "esql_data.h"
#include "esql_res.h"
#include "esql_field.h"

#include <stdint.h>
#if !defined(__cplusplus)
# include <stdbool.h>
#endif

#ifdef  __cplusplus
extern "C" {
#endif

typedef struct st_esql_methods
{
  bool (*read_query_result)(ESQL *esql);
  bool (*advanced_command) (ESQL *esql,
                           enum enum_server_command command,
                           const unsigned char *header,
                           uint32_t header_length,
                           const unsigned char *arg,
                           uint32_t arg_length,
                           bool skip_check);
  ESQL_DATA *(*read_rows)(ESQL *esql, ESQL_FIELD *esql_fields,
                             uint32_t fields);
  ESQL_RES * (*use_result)(ESQL *sql);
  void (*fetch_lengths)(uint32_t *to,ESQL_ROW column,
                        uint32_t field_count);
  void (*flush_use_result)(ESQL *esql);
  ESQL_FIELD * (*list_fields)(ESQL *esql);
  int32_t (*unbuffered_fetch)(ESQL *esql, char **row);
  const char *(*read_statistics)(ESQL *esql);
  bool (*next_result)(ESQL *esql);
} ESQL_METHODS;

static inline int32_t simple_command(ESQL *esql, enum enum_server_command command,
                                      const unsigned char *arg, uint32_t length, bool skip_check)
{
  return (*(esql)->methods->advanced_command)(esql, command, 0,
                        0, arg, length, skip_check);
}

#ifdef  __cplusplus
}
#endif

#endif /* __LIBCLIENT_METHODS_h__ */
